package com.dididoctor.doctor.Activity.Usercentre.MyPurse.CollectionMethods;

import android.content.Context;

import com.dididoctor.doctor.Activity.ConstantValue;
import com.dididoctor.doctor.Bean.Token;
import com.dididoctor.doctor.Http.MyHttpResponseHandler;
import com.dididoctor.doctor.MV.BasePresenter;
import com.dididoctor.doctor.MV.BusinessClient;
import com.dididoctor.doctor.MV.Response;
import com.dididoctor.doctor.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @version 2.0
 * @类描述： 登陆页
 * @项目名称：ddgh
 * @类名称： loginActivity
 * @包名称： com.doudoukeji.service.Activity.login
 * @创建人：张强 boy
 * @创建时间：2016/3/7 16:40
 * @修改人：
 * @修改时间：2016/3/7 16:40
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class AddCollcetionMethodsPresenter extends BasePresenter {
    private AddCollectionMethodsView view;

    public AddCollcetionMethodsPresenter(Context context, AddCollectionMethodsView view) {
        super(context, view);
        this.view = view;
    }

    public void lunch() {
        RequestParams params = new RequestParams();
        params.put("userId", Token.getUserId());
        params.put("token", Token.getToken());
        BusinessClient.post(ConstantValue.banklist, params, new MyHttpResponseHandler(view) {
            private List<Map<String, String>> maps = new ArrayList<Map<String, String>>();
            private List<BankBean> bankBeans = new ArrayList<BankBean>();

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    maps = response.getListData("bankList");
                    for (Map<String, String> map : maps) {
                        BankBean bean = new BankBean();
                        bean.setBankName(Util.toString(map.get("bankName")));
                        bean.setBankId(Util.toString(map.get("bankId")));
                        bankBeans.add(bean);
                    }
                    view.succed(bankBeans);
                } else {
                    view.showToastMessage(response.getMsg());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.fail();
            }
        });
    }


    public void addCard(String bankNo,String bankId) {
        RequestParams params = new RequestParams();
        params.put("userId", Token.getUserId());
        params.put("token", Token.getToken());
        params.put("bankNo", bankNo);
        params.put("bankId",bankId);
        BusinessClient.post(ConstantValue.addType, params, new MyHttpResponseHandler(view) {
            private List<Map<String, String>> maps = new ArrayList<Map<String, String>>();
            private List<BankBean> bankBeans = new ArrayList<BankBean>();

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    view.addSucessed();
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.showToastMessage("添加银行卡失败，请稍后再试");
            }
        });
    }
}
